﻿// JavaScript Document
$(document).ready(function () {

    //Sidebar Accordion Menu:

    $("#main-nav li ul").hide(); // Hide all sub menus
    $("#main-nav li a.current").parent().find("ul").slideToggle("slow"); // Slide down the current menu item's sub menu

    $("#main-nav li a.nav-top-item").click(// When a top menu item is clicked...
        function () {
            $(this).parent().siblings().find("ul").slideUp("normal"); // Slide up all sub menus except the one clicked
            $(this).next().slideToggle("normal"); // Slide down the clicked sub menu
            return false;
        }
    );

    $("#main-nav li a.no-submenu").click(// When a menu item with no sub menu is clicked...
        function () {
            window.location.href = (this.href); // Just open the link instead of a sub menu
            return false;
        }
    );

    // Sidebar Accordion Menu Hover Effect:

    $("#main-nav li .nav-top-item").hover(
        function () {
            $(this).stop().animate({ paddingRight: "25px" }, 200);
        },
        function () {
            $(this).stop().animate({ paddingRight: "15px" });
        }
    );

    //Minimize Content Box

    $(".content-box-header h3").css({ "cursor": "s-resize" }); // Give the h3 in Content Box Header a different cursor
    $(".closed-box .content-box-content").hide(); // Hide the content of the header if it has the class "closed"
    $(".closed-box .content-box-tabs").hide(); // Hide the tabs in the header if it has the class "closed"

    $(".content-box-header h3").click(// When the h3 is clicked...
        function () {
            $(this).parent().next().toggle(); // Toggle the Content Box
            $(this).parent().parent().toggleClass("closed-box"); // Toggle the class "closed-box" on the content box
            $(this).parent().find(".content-box-tabs").toggle(); // Toggle the tabs
        }
    );

    //Close button:

    $(".close").click(
        function () {
            $(this).parent().fadeTo(400, 0, function () { // Links with the class "close" will close parent
                $(this).slideUp(400);
            });
            return false;
        }
    );

});

// Remove Element

function removeNotification() {
    var tmp = $(".notification").length;
    if (tmp > 0) {
        $(".notification:last").animate({ opacity: '0' }, 600, function () {
            $(this).slideUp(400, function () {
                $(this).remove();
                setTimeout(removeNotification, 10000);
            });
        });
    }
}

function ShowNotification(data) {
    if (data.length == 0) return;
    
    var icon = '';
    if (data.err == 1)
        icon = 'error';
    else if (data.err == 0)
        icon = 'success';

    var result = '<div class="notification ' + icon + ' png_bg"><a href="#" class="close">' +
        '<img src="/Areas/Backend/Content/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a><div>' +
        '<table cellpadding="3" cellspacing="3"><tr><td nowrap="nowrap">Update at :</td><td><i>' + (new Date()) + '</i></td></tr>' +
        '<tr><td>Module :</td><td>' + data.module + '</td></tr><tr><td>Message :</td><td>' + data.msg + '</td></tr></table></div></div>';
    $('.notifi').before(result);
    $(".notification a.close").click(
                    function () {
                        $(this).parent().fadeTo(400, 0, function () { // Links with the class "close" will close parent
                            $(this).slideUp(400, function () {
                                $(this).remove();
                            });
                        });
                        return false;
                    });
    setTimeout(removeNotification, 10000);
}